﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Database;

namespace WindowsFormsApplication1
{
    public partial class FormUserList : Form
    {

        List<string> items = new List<string>();
        List<User> users;
        FormMain parent;

        public FormUserList(FormMain pt)
        {
            InitializeComponent();

            parent = pt;
            //users = parent.forumService.getUserList();
            //listBox1.DataSource = users;
            pt.forumService.getUserList(this);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int r = listBox1.SelectedIndex;
            if (String.IsNullOrEmpty(maskedTextBox1.Text))
                new FormError("the sub forum field is empty!").Show();
            else
                parent.forumService.promote(users.ElementAt(r).getUserName(),maskedTextBox1.Text);
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        internal void updateUserList(List<User> uList)
        {
            List<string> toDisplay= new List<string>();
            foreach (User user in uList)
            {
                toDisplay.Add(user.getUserName());
            }

            listBox1.DataSource = toDisplay;
            users = uList;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            int r = listBox1.SelectedIndex;
            if (String.IsNullOrEmpty(maskedTextBox1.Text) || String.IsNullOrEmpty(maskedTextBox2.Text))
                new FormError("one of the fields is empty!").Show();
            else
                parent.forumService.exchangeModerator(users.ElementAt(r).getUserName(), maskedTextBox2.Text, maskedTextBox1.Text);
        }

    }
}
